/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.web.servlet;

import com.web.daoimpl.CourseDaoImpl;
import com.web.daoimpl.StudentDaoImpl;
import com.web.entity.Course;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 * @author liqianru
 */
@WebServlet("/operaCourse")
public class Admin_operateCourse extends HttpServlet {

    CourseDaoImpl service=new CourseDaoImpl();
    StudentDaoImpl sservice=new StudentDaoImpl();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String action=req.getParameter("action");
        
        HttpSession session=req.getSession();
        int rows=0;
        if(req.getParameter("action").equals("add")){
            int courseid=Integer.valueOf(req.getParameter("courseid"));
            String coursename=req.getParameter("coursename");
            int tid=Integer.valueOf(req.getParameter("tid"));
            Course course=new Course(courseid,coursename,tid,null);
            rows=service.addCourse(course);
            System.out.println("添加课程成功--"+rows);
        }
        
        if(action.equals("deleteCourse")){
            int courseid=Integer.valueOf(req.getParameter("cid"));
            rows=service.deleteCourse(courseid);
            //
            System.out.println("删除成功--"+rows);
            resp.getWriter().print(rows);
           
        }
        if(action.equals("updateGrade")){
            String sid=req.getParameter("sid");
            String coursename=req.getParameter("coursename");
            int grade=Integer.valueOf(req.getParameter("grade"));
            rows=sservice.updateGrade(sid, grade,coursename);
            resp.getWriter().print(rows);
        }
        if(action.equals("updateCourse")){
            int courseid=Integer.valueOf(req.getParameter("courseid"));
            int tid=Integer.valueOf(req.getParameter("tid"));
            rows=service.updateCourse(courseid, tid);
            resp.getWriter().print(rows);
         
        }
        if(action.equals("updateSchedule")){
            int courseid=Integer.valueOf(req.getParameter("courseid"));
            int tid=Integer.valueOf(req.getParameter("tid"));
            String classid=req.getParameter("classid");
            rows=service.updateSchedule(classid, tid, courseid);
            System.out.println();
            resp.getWriter().print(rows);
        
        }
        if(action.equals("addSchedule")){
            int tid=Integer.valueOf(req.getParameter("tid"));
            String classid=req.getParameter("classid");
            int courseid=Integer.valueOf(req.getParameter("courseid"));
            rows=service.addSchedule(classid, tid, courseid);
            resp.getWriter().print(rows);
        }
        if(action.equals("deleteSchedule")){
            System.out.println(action);
            int courseid=Integer.valueOf(req.getParameter("cid"));
            rows=service.deleteSchedule(courseid);
            System.out.println(rows);
            resp.getWriter().print(rows);
        }
        if(action.equals("isrepeatCourse")){
            int courseid=Integer.valueOf(req.getParameter("courseid"));
            int isrepeatCourse=service.isrepeatCourseid(courseid);
            System.out.println(isrepeatCourse);
            resp.getWriter().print(isrepeatCourse);
        }
    }
    
    
}
